#include "gaia_common.h"
#include "cJSON.h"

/********************************************************
 * 函数名：gaia_parse_uri
 * 函数功能：解析post过来的json，解析后的数据存放在结构体HOST里
 * 函数返回值：结构体HOST,解析失败返回NULL
 *******************************************************/
HOST *gaia_parse_uri(int flags,const char *uri)
{
  cJSON *root;
  int value_int;
  char *value_string = NULL;
  
  root = cJSON_Parse(uri);

  HOST *host_info;
  if( ( host_info = (HOST *)malloc(sizeof(HOST))) == NULL) 
  {
     fprintf(stderr,"malloc memory error on parse uri\n");
     return NULL;
  }


  host_info->username = cJSON_GetObjectItem(root,"username")->valuestring;
  host_info->port = cJSON_GetObjectItem(root,"port")->valueint;
  host_info->passwd = cJSON_GetObjectItem(root,"passwd")->valuestring;
  host_info->sign = cJSON_GetObjectItem(root,"sign")->valuestring;
  host_info->host = cJSON_GetObjectItem(root,"host")->valuestring;

  return host_info;
}
